package model.logic;

import java.util.Iterator;
import java.util.Vector;
/**
 * A Disjunction is a <tt>List</tt> of <tt>Conjunction</tt>s linked by logical <b>or</b>. 
 * @author Marius Tempelmeier
 *
 */
public class Disjunction {
	private final Vector<Conjunction> conjunctions;

	public Disjunction(Vector<Conjunction> conjunctions) {
		this.conjunctions = conjunctions;
	}
	
	public Disjunction() {
		this.conjunctions = new Vector<Conjunction>();
	}
	
	public void addConjunction(Conjunction p) {
			this.conjunctions.add(p);
	}
	
	public boolean derives(Disjunction d) {
		Iterator<Conjunction> i = this.conjunctions.iterator();
		while (i.hasNext()) {
			Conjunction current = i.next();
			if (!d.containsDerivableConjunction(current)) {
				return false;
			}
		}
		return true;
	}
	
	private boolean containsDerivableConjunction(final Conjunction source) {
		Iterator<Conjunction> i = this.conjunctions.iterator();
		while (i.hasNext()) {
			Conjunction current = i.next();
			if (source.derives(current)) {
				return true;
			}
		}
		return false;
	}
}
